package com.yeyks.app.controller.base.hotel;


import com.yeyks.common.ajax.AjaxResponseBody;
import com.yeyks.common.annotation.group.MyGroup;
import com.yeyks.common.utils.ObjectConvertUtil;
import com.yeyks.commonReference.append.sms.SmsService;
import com.yeyks.hotel.dal.domain.HotelApply;
import com.yeyks.hotel.param.HotelApplyParam;
import com.yeyks.hotel.service.HotelApplyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

/**
 * 酒店入住申请表 前端控制器
 *
 * @author shuai
 * @date 2019-06-28
 */
@Slf4j
@Api(tags = "酒店入住申请表接口", description = "酒店入住申请表接口")
@RestController
@RequestMapping("/hotelApply")
public class HotelApplyController {
    @Autowired
    private HotelApplyService hotelApplyService;
    @Autowired
    private SmsService smsService;

    @ApiOperation(value = "新增酒店入住申请")
    @PostMapping("/insert")
    public AjaxResponseBody getAddressByParentCode(@Validated(MyGroup.class) HotelApplyParam param) {
        HotelApply hotelApply = ObjectConvertUtil.convertObject(param, HotelApply.class);
        hotelApply.setStatus(HotelApply.Status.WAIT.value());
        Date date = new Date();
        hotelApply.setUpdatedTime(date);
        hotelApply.setCreatedTime(date);
        if (hotelApplyService.save(hotelApply)) {
            //保存成功后给用户发送一条短信
            if (smsService.sendUserToWait(hotelApply.getPhone())) {
                log.error("填写入住申请发送短信失败phone = {}", hotelApply.getPhone());
            }
            return AjaxResponseBody.success();
        }
        return AjaxResponseBody.failed("数据插入失败");
    }

}
